package com.fancy.learncenter.ui.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.TeachersBean;
import com.fancy.learncenter.ui.activity.CartoonQueryTeacherActivity;
import com.fancy.learncenter.ui.activity.CartoonTeacherClassDetailActivity;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;
import com.fancy.learncenter.ui.view.CartoonTeacherPopupWindow;

import java.util.List;

/**
 * Created by hyy on 2018/1/25.
 * describe as
 */

public class CartoonTeacherAdapter extends CommonRecycleViewAdapter<TeachersBean> {

    public Activity context;


    public CartoonTeacherAdapter(Activity mContext, List<TeachersBean> itemDatas) {
        super(mContext, R.layout.activity_cartoon_teacher_item, itemDatas);
        this.classId = classId;
        this.context = mContext;
    }

    String classId;

    public ClickCallBack getClickListener() {
        return clickListener;
    }

    public void setClickListener(ClickCallBack clickListener) {
        this.clickListener = clickListener;
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final TeachersBean item, final int position) {

        SimpleDraweeView class_pic = customViewHold.getView(R.id.class_pic);
        class_pic.setImageURI(item.getImageUrl());

        TextView name = customViewHold.getView(R.id.name);
        name.setText(item.getName());

        RelativeLayout status = customViewHold.getView(R.id.status);
        if ("0".equals(item.getStatus())) {
            status.setVisibility(View.VISIBLE);
        } else {
            status.setVisibility(View.GONE);
        }

        if (position == (getItemCount() - 1)) {
            customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, CartoonQueryTeacherActivity.class);

                    intent.putExtra(CartoonTeacherClassDetailActivity.CLASS_ID_KEY, item.getId());
                    intent.putExtra(CartoonQueryTeacherActivity.FLAG_KEY, "1");

                    mContext.startActivity(intent);
                }
            });
        } else {

            customViewHold.getRoorView().setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View view) {
                    if (clickListener != null) {
                        clickListener.onlongclickCallBack(item,position);
                    }
                    return true;
                }
            });

            customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (clickListener != null) {
                        clickListener.onclickCallBack(item);
                    }
                }
            });


        }

    }

    private ClickCallBack clickListener;


    public interface ClickCallBack {
        abstract void onclickCallBack(TeachersBean item);
        abstract void onlongclickCallBack(TeachersBean item,int position);

    }
}

